package cj.web.prize.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.prize.domain.Prize;

/**
 * 
 * @author 
 *
 */
@DAO
public interface PrizeDAO{
	
	@SQL("SELECT * FROM Prize #if(:t.activeName!=''){WHERE ActiveName like '%##(:t.activeName)%' } ORDER BY ID LIMIT :t.start,:t.length ")
    List<Prize> query(@SQLParam("t") Prize prize);
	
	@SQL("SELECT count(*) FROM Prize #if(:t.activeName!=''){WHERE ActiveName like '%##(:t.activeName)%' } ")
    int querySize(@SQLParam("t") Prize prize);
    
    @SQL("select * from Prize where id=:1")
    Prize queryById(int id);
    
    @SQL("UPDATE Prize SET activeName=:4,StartAT=:2,EndAT=:3 WHERE ID=:1")
    void update(int id,String startAT,String endAT,String activeName);
    
    //以下SQL是用来判断活动是否开始
    @SQL("select count(1) from Prize "
    		+ "where id =:1 "
    		+ "and StartAT < date_format(:2,'%Y-%m-%d %H:%i:%s') "
    		+ "and EndAT > date_format(:2,'%Y-%m-%d %H:%i:%s')")
    int queryByIdAndDate(int id,String date);
}